package com.jyw.web.controller.system;

import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.TableDataInfo;
import com.jyw.common.enums.BusinessType;
import com.jyw.common.utils.poi.ExcelUtil;
import com.jyw.system.domain.SysFormConfig;
import com.jyw.system.domain.vo.SysFormConfigVo;
import com.jyw.system.domain.vo.SysFormMenuVo;
import com.jyw.system.service.ISysFormConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 系统表单配置Controller
 *
 * @author ZhangCheng
 * @date 2023-08-10
 */
@Api(tags = "系统表单配置Api")
@RestController
@RequestMapping("/system/formConfig")
public class SysFormConfigController extends BaseController {

    @Autowired
    private ISysFormConfigService sysFormConfigService;

    /**
     * 查询系统表单配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:formConfig:list')")
    @GetMapping("/list")
    @ApiOperation("查询系统表单配置列表")
    public TableDataInfo<SysFormConfig> list(SysFormConfig sysFormConfig) {
        startPage();
        List<SysFormConfig> list = sysFormConfigService.selectSysFormConfigList(sysFormConfig);
        return getDataTable(list);
    }

    /**
     * 查询所有表单配置菜单
     */
    @GetMapping("/queryMenuList")
    @ApiOperation("查询所有表单配置菜单")
    public CommonResult<List<SysFormMenuVo>> queryMenuList() {
        List<SysFormMenuVo> list = sysFormConfigService.queryMenuList();
        return CommonResult.success((list));
    }

    /**
     * 根据菜单ID查询系统表单配置
     *
     * @param menuId
     * @return
     */
    @GetMapping("/queryListByMenuId")
    @ApiOperation("根据菜单ID查询系统表单配置")
    public CommonResult<List<SysFormConfigVo>> queryListByMenuId(Long menuId) {
        List<SysFormConfigVo> list = sysFormConfigService.queryListByMenuId(menuId);
        return CommonResult.success((list));
    }

    /**
     * 导出系统表单配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:formConfig:export')")
    @Log(title = "系统表单配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出系统表单配置列表")
    public void export(HttpServletResponse response, SysFormConfig sysFormConfig) {
        List<SysFormConfig> list = sysFormConfigService.selectSysFormConfigList(sysFormConfig);
        ExcelUtil<SysFormConfig> util = new ExcelUtil<SysFormConfig>(SysFormConfig.class);
        util.exportExcel(response, list, "系统表单配置数据");
    }

    /**
     * 获取系统表单配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:formConfig:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取系统表单配置详细信息")
    public CommonResult<SysFormConfig> getInfo(@PathVariable("id") Long id) {
        return CommonResult.success(sysFormConfigService.selectSysFormConfigById(id));
    }

    /**
     * 新增系统表单配置
     */
    @PreAuthorize("@ss.hasPermi('system:formConfig:add')")
    @Log(title = "系统表单配置", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    @ApiOperation("新增系统表单配置")
    public CommonResult add(@RequestBody SysFormConfig sysFormConfig) {
        return CommonResult.success(sysFormConfigService.insertSysFormConfig(sysFormConfig));
    }

    /**
     * 修改系统表单配置
     */
    @PreAuthorize("@ss.hasPermi('system:formConfig:edit')")
    @Log(title = "系统表单配置", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    @ApiOperation("修改系统表单配置")
    public CommonResult edit(@RequestBody SysFormConfig sysFormConfig) {
        return CommonResult.success(sysFormConfigService.updateSysFormConfig(sysFormConfig));
    }

    /**
     * 删除系统表单配置
     */
    @PreAuthorize("@ss.hasPermi('system:formConfig:remove')")
    @Log(title = "系统表单配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除系统表单配置")
    public CommonResult remove(@PathVariable Long[] ids) {
        return CommonResult.success(sysFormConfigService.deleteSysFormConfigByIds(ids));
    }
}
